﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PhotoGallery.Core.Business.RoleIndexModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    重庆市公安图片管理系统 - 角色管理
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div id="list-right">
        <table width="100%" cellspacing="5" cellpadding="0" border="0">
            <tbody>
                <tr>
                    <td valign="top" class="s-box" id="list-left" style="width: 200px">
                        <div class="head">
                            角色列表</div>
                        <div class="con">
                            <table class="info-table">
                                <tbody>
                                    <% if (Model.Roles != null)
                                       {
                                           foreach (var item in Model.Roles)
                                           { %>
                                    <tr>
                                        <td>
                                            <%:Html.ActionLink(item.Name, "index", new { index = item.Id })%>
                                        </td>
                                    </tr>
                                    <% }
                                       } %>
                                </tbody>
                            </table>
                        </div>
                    </td>
                    <td>
                        <div class="con-box">
                            <div class="head">
                                <h2>
                                    <a href='<%= Url.Action("Index") %>'>权限管理</a> &gt 角色管理
                                </h2>
                                <span class="sexybutton" id="btn-search"><span><span>
                                    <input type="button" class="add" value="添加" onclick="window.location.href='<%= Url.Action("Add") %>'" /></span></span></span>
                                 <% if(Model.Current!=null) {%><span class="sexybutton" id="btn-delete"><span><span>
                                   <input type="button" class="delete" value="删除" onclick="window.location.href='<%= Url.Action("Delete") %>/<%:Model.Current.Id  %>'" /></span></span></span>
                                <span class="sexybutton" id="btn-edit"><span><span>
                                    <input type="button" class="edit" value="修改" onclick="window.location.href='<%= Url.Action("Edit") %>/<%:Model.Current.Id  %>'" /></span></span></span><%} %>
                            </div>
                            <div class="con">
                                <div class="box">
                                    <div class="info-icon info">
                                        <ul>
                                            <li>所有的角色在有与之相关联的功能都被删除<span style="font-weight: bold;">移除</span>后<span class="red">才能删除</span></li>
                                            <li>请认真考虑角色和功能之间的组合关系。</li>
                                        </ul>
                                    </div>
                                </div>
                                <div class="box attributes">
                                    <div class="attr-title">
                                        <span>基础信息</span></div>
                                    <ul class="detail-info-list clearfix">
                                        
                                        <li><span>角色名称：<% if(Model.Current!=null) {%><%: Html.DisplayTextFor(m => m.Current.Name)%><%} %></span></li>
                                        <li><span>添加日期：<% if(Model.Current!=null) {%><%: Html.DisplayTextFor(m => m.Current.AddDate)%><%} %></span></li>
                                        <li><span>描述：<% if(Model.Current!=null) {%><%: Html.DisplayTextFor(m => m.Current.Description)%><%} %></span></li>
                                        <li><span>状态：<% if(Model.Current!=null) {%><%: Html.DisplayTextFor(m => m.Current.StatusText)%><%} %></span></li>
                                    </ul>
                                </div>
                                <div class="attributes margint5">
                                    <div class="attr-title">
                                        <span>功能列表</span> <a class="sexybutton" id="function-save"><span><span><em class="add">
                                            保存</em></span></span></a>
                                    </div>
                                </div>
                                <div class="clearfix box">
                                    <!-- 待选角色 -->
                                    <table id="selected-panel" style="text-align: center" cellspacing="0" cellpadding="0"
                                        class="info-table">
                                        <thead>
                                            <tr>
                                                <th>
                                                    <input type="checkbox" id="chkall" />
                                                </th>
                                                <th>
                                                    功能名称
                                                </th>
                                                <th>
                                                    Controller
                                                </th>
                                                <th>
                                                    Action
                                                </th>
                                                <th>
                                                    状态
                                                </th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <%
                                                    
                                                foreach (var item in Model.Operations.OrderBy(item => item.Controller).OrderBy(item => item.Action))
                                                {                                            
                                            %>
                                            <tr id="<%: Html.Encode(item.Id) %>">
                                                <td>
                                                    <input type="checkbox" <%: Model.Current!=null&&Model.Current.OperationIds.Contains(item.Id)?"checked='checked'":string.Empty %>" />
                                                </td>
                                                <td>
                                                    <%--功能名称--%>
                                                    <%=   Html.Encode(item.Name) %>
                                                </td>
                                                <td>
                                                    <%--  Controller--%>
                                                    <%= Html.Encode(item.Controller) %>
                                                </td>
                                                <td>
                                                    <%--  Action--%>
                                                    <%=  Html.Encode(item.Action) %>
                                                </td>
                                                <td>
                                                    <%-- 状态--%>
                                                    <%=  Html.Encode(item.Status==0?"正常":"禁用") %>
                                                </td>
                                            </tr>
                                            <%
                                                } %>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="StyleContent" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript" charset="utf-8">
        $(function () {
            /////////////////////////////////
            // 全选
            ////////////////////////////////
            (function () {
                var chkall = $("#selected-panel>thead>tr>th>input:checkbox");

                chkall.live("click", function () {
                    $("#selected-panel>tbody input:checkbox").attr("checked", $(this).is(":checked"));
                    if ($("#selected-panel>tbody input:checkbox:checked").length > 0)
                        $("#deselect-function").attr("disabled", "");
                    else
                        $("#deselect-function").attr("disabled", "disabled");

                });

                $("#selected-panel>tbody input:checkbox").live("click", function () {

                    var total = $("#selected-panel>tbody input:checkbox"), checked = $("#selected-panel>tbody input:checkbox:checked");

                    if (checked.length === total.length && !chkall.is(":checked"))
                        chkall.attr("checked", true);

                    if (checked.length === 0 && chkall.is(":checked"))
                        chkall.attr("checked", false);

                    if (checked.length > 0)
                        $("#deselect-function").attr("disabled", "");
                    else
                        $("#deselect-function").attr("disabled", "disabled");
                });
            })();




            (function () {
                $("#function-save").click(function () {
                    var $list = [];

                    $("#selected-panel>tbody>tr").each(function () {
                        if ($(this).find("input:checkbox").is(":checked"))
                            $list.push($(this).attr("id"));
                    });
                    $.ajax({
                        url: '<%: Url.Action("Save","Role",new {id= Model.Current!=null ? Model.Current.Id :0}) %>',
                        type: "POST",
                        dataType: "json",
                        data: {
                            operations: JSON.stringify($list)
                        },
                        success: function (data) {
                            if (data.success) {
                                cy.ui.showResult({ content: data.message, disappear: 5000 });
                            } else {
                                cy.ui.showResult({ content: data.message, disappear: 5000, className: 'cy-ui-results error' });
                            }
                        }
                    });
                });

            })();
        });
    
    </script>
</asp:Content>
